<!DOCTYPE html>
<html lang="zh-CN">
  <head>
  <meta charset="UTF-8">
  <meta 
    name="viewport"
    content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
  <meta 
    http-equiv="X-UA-Compatible" 
    content="ie=edge">
  <meta 
    name="theme-color" 
    content="#fff" 
    id="theme-color">
  <meta 
    name="description" 
    content="hexoDemo用于介绍如何使用hexo">
  <link 
    rel="icon" 
    href="/">
  <title>16-内置对象：Number和Math</title>
  
    
      <meta 
        property="og:title" 
        content="16-内置对象：Number和Math">
    
    
      <meta 
        property="og:url" 
        content="https://zwl5670.gitee.io/2004/03/01/04-JavaScript%E5%9F%BA%E7%A1%80/16-%E5%86%85%E7%BD%AE%E5%AF%B9%E8%B1%A1%EF%BC%9ANumber%E5%92%8CMath/index.html">
    
    
      <meta 
        property="og:img" 
        content="https://img.songhn.com/img/Y67gdd.png">
    
    
      <meta 
        property="og:img" 
        content="hexoDemo用于介绍如何使用hexo">
    
    
      <meta 
        property="og:type" 
        content="article">
      <meta 
        property="og:article:published_time" 
        content="2004-03-01">
      <meta 
        property="og:article:modified_time" 
        content="2023-03-14">
      <meta 
        property="og:article:author" 
        content="zwl5670">
      
        
          <meta 
            property="og:article:tag" 
            content="JS基础">
        
      
    
  
  
  <link rel="preload" href="//at.alicdn.com/t/font_1946621_i1kgafibvw.css" as="style" >
  <link rel="preload" href="//at.alicdn.com/t/font_1952792_89b4ac4k4up.css" as="style" >
  <link rel="preload" href="/css/main.css" as="style" >
  
  <link rel="modulepreload" href="//instant.page/5.1.0">
  
  <link rel="stylesheet" href="/css/main.css">
  
  <link rel="stylesheet" href="//at.alicdn.com/t/font_1946621_i1kgafibvw.css">
  
  <link rel="stylesheet" href="//at.alicdn.com/t/font_1952792_89b4ac4k4up.css">
  
  
  
    <link rel="stylesheet" href="/js/lib/lightbox/baguetteBox.min.css">
  
  <script>
    function loadScript(url, cb) {
      var script = document.createElement('script');
      script.src = url;
      if (cb) script.onload = cb;
      script.async = true;
      document.body.appendChild(script);
    }
    function loadCSS(href, data, attr) {
      var sheet = document.createElement('link');
      sheet.ref = 'stylesheet';
      sheet.href = href;
      sheet.dataset[data] = attr;
      document.head.appendChild(sheet);
    }
    function changeCSS(cssFile, data, attr) {
      var oldlink = document.querySelector(data);
      var newlink = document.createElement("link");
      newlink.setAttribute("rel", "stylesheet");
      newlink.setAttribute("href", cssFile);
      newlink.dataset.prism = attr;
      document.head.replaceChild(newlink, oldlink);
    }
  </script>
  
    
  
  <script>
    // control reverse button
    var reverseDarkList = {
      dark: 'light',
      light: 'dark'
    };
    var themeColor = {
      dark: '#1c1c1e',
      light: '#fff'
    }
    // get the data of css prefers-color-scheme
    var getCssMediaQuery = function() {
      return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
    };
    // reverse current darkmode setting function
    var reverseDarkModeSetting = function() {
      var setting = localStorage.getItem('user-color-scheme');
      if(reverseDarkList[setting]) {
        setting = reverseDarkList[setting];
      } else if(setting === null) {
        setting = reverseDarkList[getCssMediaQuery()];
      } else {
        return;
      }
      localStorage.setItem('user-color-scheme', setting);
      return setting;
    };
    // apply current darkmode setting
  </script>
  
    <script>
      var setDarkmode = function(mode) {
      var setting = mode || localStorage.getItem('user-color-scheme');
      if(setting === getCssMediaQuery()) {
        document.documentElement.removeAttribute('data-user-color-scheme');
        localStorage.removeItem('user-color-scheme');
        document.getElementById('theme-color').content = themeColor[setting];
        document.getElementById('theme-color').dataset.mode = setting;
      } else if(reverseDarkList[setting]) {
        document.documentElement.setAttribute('data-user-color-scheme', setting);
        document.getElementById('theme-color').content = themeColor[setting];
        document.getElementById('theme-color').dataset.mode = setting;
      } else {
        document.documentElement.removeAttribute('data-user-color-scheme');
        localStorage.removeItem('user-color-scheme');
        document.getElementById('theme-color').content = themeColor[getCssMediaQuery()];
        document.getElementById('theme-color').dataset.mode = getCssMediaQuery();
      }
    };
    setDarkmode();
    </script>
  
  
  
    <link rel="preload" href="/js/lib/lightbox/baguetteBox.min.js" as="script">
    <link rel="preload" href="/js/lib/lightbox/baguetteBox.min.css" as="style" >
  
  
    <link rel="preload" href="/js/lib/lozad.min.js" as="script">
  
  
  
  
  
  
<meta name="generator" content="Hexo 6.3.0"></head>

  <body>
    <div class="wrapper">
       
      <nav class="navbar">
  <div class="navbar-logo">
    <a class="navbar-logo-main" href="/">
      
      <span class="navbar-logo-dsc">前端面试</span>
      </a>
  </div>
  <div class="navbar-menu">
    
      <a 
        href="/" 
        class="navbar-menu-item">
        
          首页
        
      </a>
    
      <a 
        href="/archives" 
        class="navbar-menu-item">
        
          归档
        
      </a>
    
      <a 
        href="/tags" 
        class="navbar-menu-item">
        
          标签
        
      </a>
    
      <a 
        href="/categories" 
        class="navbar-menu-item">
        
          分类
        
      </a>
    
      <a 
        href="/about" 
        class="navbar-menu-item">
        
          关于
        
      </a>
    
      <a 
        href="/links" 
        class="navbar-menu-item">
        
          友链
        
      </a>
    
    <button 
      class="navbar-menu-item darknavbar navbar-menu-btn" 
      aria-label="Toggle dark mode"
      id="dark">
      <i class="iconfont icon-weather"></i>
    </button>
    <button 
      class="navbar-menu-item searchnavbar navbar-menu-btn" 
      aria-label="Toggle search"
      id="search">
      <!-- <i 
        class="iconfont icon-search" 
        style="font-size: 1.2rem; font-weight: 400;">
      </i> -->
      <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img"
        class="iconify iconify--ion" width="28" height="28" preserveAspectRatio="xMidYMid meet" viewBox="0 0 512 512">
        <path fill="none" stroke="currentColor" stroke-miterlimit="10" stroke-width="28"
          d="M256 80a176 176 0 1 0 176 176A176 176 0 0 0 256 80Z"></path>
        <path fill="none" stroke="currentColor" stroke-miterlimit="10" stroke-width="28"
          d="M232 160a72 72 0 1 0 72 72a72 72 0 0 0-72-72Z"></path>
        <path fill="none" stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="28"
          d="M283.64 283.64L336 336"></path>
      </svg>
    </button>
  </div>
</nav> 
      
      <div 
        id="local-search" 
        style="display: none">
        <input
          class="navbar-menu-item"
          id="search-input"
          placeholder="请输入搜索内容..." />
        <div id="search-content"></div>
      </div>
      
      <div class="section-wrap">
        <div class="container">
          <div class="columns">
            <aside class="left-column">
              
              <div class="card card-author">
                
  <img 
    src="https://img.songhn.com/img/Y67gdd.png" 
    class="author-img"
    width="88"
    height="88"
    alt="author avatar">

<p class="author-name">zwl5670</p>
<p class="author-description">前端学习资料</p>
<div class="author-message">
  <a 
    class="author-posts-count" 
    href="/archives">
    <span>215</span>
    <span>文章</span>
  </a>
  <a 
    class="author-categories-count" 
    href="/categories">
    <span>14</span>
    <span>分类</span>
  </a>
  <a 
    class="author-tags-count" 
    href="/tags">
    <span>14</span>
    <span>标签</span>
  </a>
</div>

              </div>
               <div class="sticky-tablet">
  
  
    <article class="display-when-two-columns spacer">
      <div class="card card-content toc-card">
        <div class="toc-header">
  <i 
    class="iconfont icon-menu" 
    style="padding-right: 2px;">
  </i>目录
</div>
<ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%86%85%E7%BD%AE%E5%AF%B9%E8%B1%A1-Number-%E7%9A%84%E5%B8%B8%E8%A7%81%E6%96%B9%E6%B3%95"><span class="toc-text">内置对象 Number 的常见方法</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Number-isInteger-%E5%88%A4%E6%96%AD%E6%98%AF%E5%90%A6%E4%B8%BA%E6%95%B4%E6%95%B0"><span class="toc-text">Number.isInteger() 判断是否为整数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#toFixed-%E5%B0%8F%E6%95%B0%E7%82%B9%E5%90%8E%E9%9D%A2%E4%BF%9D%E7%95%99%E5%A4%9A%E5%B0%91%E4%BD%8D"><span class="toc-text">toFixed() 小数点后面保留多少位</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%86%85%E7%BD%AE%E5%AF%B9%E8%B1%A1-Math-%E7%9A%84%E5%B8%B8%E8%A7%81%E6%96%B9%E6%B3%95"><span class="toc-text">内置对象 Math 的常见方法</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Math-abs-%EF%BC%9A%E8%8E%B7%E7%BB%9D%E5%AF%B9%E5%80%BC"><span class="toc-text">Math.abs()：获绝对值</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Math-random-%E6%96%B9%E6%B3%95%EF%BC%9A%E7%94%9F%E6%88%90%E9%9A%8F%E6%9C%BA%E6%95%B0"><span class="toc-text">Math.random() 方法：生成随机数</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%94%9F%E6%88%90-0-x-%E4%B9%8B%E9%97%B4%E7%9A%84%E9%9A%8F%E6%9C%BA%E6%95%B0"><span class="toc-text">生成 [0, x) 之间的随机数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%94%9F%E6%88%90-x-y-%E4%B9%8B%E9%97%B4%E7%9A%84%E9%9A%8F%E6%9C%BA%E6%95%B0"><span class="toc-text">生成 [x, y) 之间的随机数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E3%80%90%E9%87%8D%E8%A6%81%E3%80%91%E7%94%9F%E6%88%90-x-y-%E4%B9%8B%E9%97%B4%E7%9A%84%E9%9A%8F%E6%9C%BA%E6%95%B4%E6%95%B0"><span class="toc-text">【重要】生成 [x, y]之间的随机整数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%BE%E4%BE%8B%EF%BC%9A%E9%9A%8F%E6%9C%BA%E7%82%B9%E5%90%8D"><span class="toc-text">举例：随机点名</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#pow-%EF%BC%9A%E4%B9%98%E6%96%B9"><span class="toc-text">pow()：乘方</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#sqrt-%EF%BC%9A%E5%BC%80%E6%96%B9"><span class="toc-text">sqrt()：开方</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#url-%E7%BC%96%E7%A0%81%E5%92%8C%E8%A7%A3%E7%A0%81"><span class="toc-text">url 编码和解码</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%B5%9E%E8%B5%8F%E4%BD%9C%E8%80%85"><span class="toc-text">赞赏作者</span></a></li></ol>
      </div>
    </article>
  
  
  <article class="card card-content categories-widget">
    <div class="categories-card">
  <div class="categories-header">
    <i 
      class="iconfont icon-fenlei" 
      style="padding-right: 2px;">
    </i>分类
  </div>
  <div class="categories-list">
    
      <a href="/categories/%E5%89%8D%E7%AB%AF%E5%B7%A5%E5%85%B7/">
        <div class="categories-list-item">
          前端工具
          <span class="categories-list-item-badge">13</span>
        </div>
      </a>
    
      <a href="/categories/CSS%E5%9F%BA%E7%A1%80/">
        <div class="categories-list-item">
          CSS基础
          <span class="categories-list-item-badge">18</span>
        </div>
      </a>
    
      <a href="/categories/CSS%E8%BF%9B%E9%98%B6/">
        <div class="categories-list-item">
          CSS进阶
          <span class="categories-list-item-badge">9</span>
        </div>
      </a>
    
      <a href="/categories/HTML/">
        <div class="categories-list-item">
          HTML
          <span class="categories-list-item-badge">12</span>
        </div>
      </a>
    
      <a href="/categories/JS%E5%9F%BA%E7%A1%80/">
        <div class="categories-list-item">
          JS基础
          <span class="categories-list-item-badge">56</span>
        </div>
      </a>
    
      <a href="/categories/JS%E5%9F%BA%E7%A1%80ES6/">
        <div class="categories-list-item">
          JS基础ES6
          <span class="categories-list-item-badge">10</span>
        </div>
      </a>
    
      <a href="/categories/JS%E5%9F%BA%E7%A1%80%E5%BC%82%E6%AD%A5/">
        <div class="categories-list-item">
          JS基础异步
          <span class="categories-list-item-badge">11</span>
        </div>
      </a>
    
      <a href="/categories/JS%E8%BF%9B%E9%98%B6/">
        <div class="categories-list-item">
          JS进阶
          <span class="categories-list-item-badge">11</span>
        </div>
      </a>
    
      <a href="/categories/%E7%A7%BB%E5%8A%A8web/">
        <div class="categories-list-item">
          移动web
          <span class="categories-list-item-badge">3</span>
        </div>
      </a>
    
      <a href="/categories/CSS%E5%92%8CDOM/">
        <div class="categories-list-item">
          CSS和DOM
          <span class="categories-list-item-badge">6</span>
        </div>
      </a>
    
      <a href="/categories/Node/">
        <div class="categories-list-item">
          Node
          <span class="categories-list-item-badge">16</span>
        </div>
      </a>
    
      <a href="/categories/Vue%E5%9F%BA%E7%A1%80/">
        <div class="categories-list-item">
          Vue基础
          <span class="categories-list-item-badge">15</span>
        </div>
      </a>
    
      <a href="/categories/%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96/">
        <div class="categories-list-item">
          性能优化
          <span class="categories-list-item-badge">7</span>
        </div>
      </a>
    
      <a href="/categories/%E5%89%8D%E7%AB%AF%E5%B7%A5%E7%A8%8B%E5%8C%96/">
        <div class="categories-list-item">
          前端工程化
          <span class="categories-list-item-badge">8</span>
        </div>
      </a>
    
  </div>
</div>
  </article>
  
  <article class="card card-content tags-widget">
    <div class="tags-card">
  <div class="tags-header">
    <i 
      class="iconfont icon-biaoqian" 
      style="padding-right: 2px;">
    </i>热门标签
  </div>
  <div class="tags-list">
    
      <a 
        href="/tags/JS%E5%9F%BA%E7%A1%80/" 
        title="JS基础">
        <div class="tags-list-item">JS基础</div>
      </a>
    
      <a 
        href="/tags/CSS%E5%9F%BA%E7%A1%80/" 
        title="CSS基础">
        <div class="tags-list-item">CSS基础</div>
      </a>
    
      <a 
        href="/tags/Node/" 
        title="Node">
        <div class="tags-list-item">Node</div>
      </a>
    
      <a 
        href="/tags/Vue%E5%9F%BA%E7%A1%80/" 
        title="Vue基础">
        <div class="tags-list-item">Vue基础</div>
      </a>
    
      <a 
        href="/tags/%E5%89%8D%E7%AB%AF%E5%B7%A5%E5%85%B7/" 
        title="前端工具">
        <div class="tags-list-item">前端工具</div>
      </a>
    
      <a 
        href="/tags/HTML/" 
        title="HTML">
        <div class="tags-list-item">HTML</div>
      </a>
    
      <a 
        href="/tags/JS%E8%BF%9B%E9%98%B6/" 
        title="JS进阶">
        <div class="tags-list-item">JS进阶</div>
      </a>
    
      <a 
        href="/tags/JS%E5%9F%BA%E7%A1%80%E5%BC%82%E6%AD%A5/" 
        title="JS基础异步">
        <div class="tags-list-item">JS基础异步</div>
      </a>
    
      <a 
        href="/tags/JS%E5%9F%BA%E7%A1%80ES6/" 
        title="JS基础ES6">
        <div class="tags-list-item">JS基础ES6</div>
      </a>
    
      <a 
        href="/tags/CSS%E8%BF%9B%E9%98%B6/" 
        title="CSS进阶">
        <div class="tags-list-item">CSS进阶</div>
      </a>
    
      <a 
        href="/tags/%E5%89%8D%E7%AB%AF%E5%B7%A5%E7%A8%8B%E5%8C%96/" 
        title="前端工程化">
        <div class="tags-list-item">前端工程化</div>
      </a>
    
      <a 
        href="/tags/%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96/" 
        title="性能优化">
        <div class="tags-list-item">性能优化</div>
      </a>
    
      <a 
        href="/tags/CSS%E5%92%8CDOM/" 
        title="CSS和DOM">
        <div class="tags-list-item">CSS和DOM</div>
      </a>
    
      <a 
        href="/tags/%E7%A7%BB%E5%8A%A8web/" 
        title="移动web">
        <div class="tags-list-item">移动web</div>
      </a>
    
  </div>
</div>
  </article>
  
  
</div>
            </aside>
            <main class="main-column">
              
<article class="card card-content">
  <header>
    <h1 class="post-title">
      16-内置对象：Number和Math
    </h1>
  </header>
  <div class="post-meta post-show-meta">
    <time datetime="2004-02-29T16:00:00.000Z">
      <i 
        class="iconfont icon-calendar" 
        style="margin-right: 2px;">
      </i>
      <span>2004-03-01</span>
    </time>
    
      <span class="dot"></span>
      
        <a 
          href="/categories/JS%E5%9F%BA%E7%A1%80/" 
          class="post-meta-link">
          JS基础
        </a>
      
    
    
      <span class="dot"></span>
      <span>1.2k 字</span>
    
  </div>
  
    <div 
      class="post-meta post-show-meta" 
      style="margin-top: -10px;">
      <div style="display: flex; align-items: center;">
        <i 
          class="iconfont icon-biaoqian" 
          style="margin-right: 2px; font-size: 1.15rem;">
        </i>
        
          
          <a 
            href="/tags/JS%E5%9F%BA%E7%A1%80/" 
            class="post-meta-link">
            JS基础
          </a>
        
      </div>
    </div>
  
  </header>
  <div 
    id="section" 
    class="post-content">
    <p><ArticleTopAd></ArticleTopAd></p>
<h2 id="内置对象-Number-的常见方法"><a href="#内置对象-Number-的常见方法" class="headerlink" title="内置对象 Number 的常见方法"></a>内置对象 Number 的常见方法</h2><h3 id="Number-isInteger-判断是否为整数"><a href="#Number-isInteger-判断是否为整数" class="headerlink" title="Number.isInteger() 判断是否为整数"></a>Number.isInteger() 判断是否为整数</h3><p>语法：</p>
<pre class="highlight"><span class="line">布尔值 = Number.isInteger(数字);</span><br></pre>


<h3 id="toFixed-小数点后面保留多少位"><a href="#toFixed-小数点后面保留多少位" class="headerlink" title="toFixed() 小数点后面保留多少位"></a>toFixed() 小数点后面保留多少位</h3><p>语法：</p>
<pre class="highlight"><span class="line">字符串 = myNum.<span class="title function_">toFixed</span>(num);</span><br></pre>

<p>解释：将数字 myNum 的小数点后面保留 num 位小数（四舍五入），并返回。不会改变原数字。注意，<strong>返回结果是字符串</strong>。</p>
<p>参数 num：指定了小数点后面的位数。</p>
<p>举例：</p>
<pre class="highlight"><span class="line"><span class="keyword">let</span> num = <span class="number">3.456</span>;</span><br><span class="line"><span class="keyword">let</span> num2 = num.<span class="title function_">toFixed</span>(<span class="number">2</span>);</span><br><span class="line"></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(num); <span class="comment">// 打印结果：3.456</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(num2); <span class="comment">// 打印结果：3.46</span></span><br><span class="line"></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="keyword">typeof</span> num); <span class="comment">// number</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="keyword">typeof</span> num2); <span class="comment">// string</span></span><br></pre>

<p>上方代码中，<code>num2</code>的结果是3.46，但是请注意，<code>num</code>的类型Number型，而<code>num2</code>的类型却是String型。</p>
<h2 id="内置对象-Math-的常见方法"><a href="#内置对象-Math-的常见方法" class="headerlink" title="内置对象 Math 的常见方法"></a>内置对象 Math 的常见方法</h2><p>Math 和其他的对象不同，它不是一个构造函数，不需要创建对象。所以我们不需要 通过 new 来调用，而是直接使用里面的属性和方法即可。</p>
<p>Math属于一个工具类，里面封装了数学运算相关的属性和方法。如下：</p>
<table>
<thead>
<tr>
<th align="left">方法</th>
<th align="left">描述</th>
<th align="left">备注</th>
</tr>
</thead>
<tbody><tr>
<td align="left">Math.PI</td>
<td align="left">圆周率</td>
<td align="left">Math对象的属性</td>
</tr>
<tr>
<td align="left">Math.abs()</td>
<td align="left"><strong>返回绝对值</strong></td>
<td align="left"></td>
</tr>
<tr>
<td align="left">Math.random()</td>
<td align="left">生成0-1之间的<strong>随机浮点数</strong></td>
<td align="left">取值范围是 [0，1)</td>
</tr>
<tr>
<td align="left">Math.floor()</td>
<td align="left"><strong>向下取整</strong>（往小取值）</td>
<td align="left"></td>
</tr>
<tr>
<td align="left">Math.ceil()</td>
<td align="left"><strong>向上取整</strong>（往大取值）</td>
<td align="left"></td>
</tr>
<tr>
<td align="left">Math.round()</td>
<td align="left">四舍五入取整（正数四舍五入，负数五舍六入）</td>
<td align="left"></td>
</tr>
<tr>
<td align="left">Math.max(x, y, z)</td>
<td align="left">返回多个数中的最大值</td>
<td align="left"></td>
</tr>
<tr>
<td align="left">Math.min(x, y, z)</td>
<td align="left">返回多个数中的最小值</td>
<td align="left"></td>
</tr>
<tr>
<td align="left">Math.pow(x,y)</td>
<td align="left">乘方：返回 x 的 y 次幂</td>
<td align="left"></td>
</tr>
<tr>
<td align="left">Math.sqrt()</td>
<td align="left">开方：对一个数进行开方运算</td>
<td align="left"></td>
</tr>
</tbody></table>
<p><strong>举例</strong>：</p>
<pre class="highlight"><span class="line"><span class="keyword">var</span> num = -<span class="number">0.6</span>;</span><br><span class="line"></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="title class_">Math</span>.<span class="title function_">abs</span>(num));        <span class="comment">//取绝对值</span></span><br><span class="line"></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="title class_">Math</span>.<span class="title function_">floor</span>(num));      <span class="comment">//向下取整，向小取</span></span><br><span class="line"></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="title class_">Math</span>.<span class="title function_">ceil</span>(num));       <span class="comment">//向上取整，向大取</span></span><br><span class="line"></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="title class_">Math</span>.<span class="title function_">round</span>(num));      <span class="comment">//四舍五入取整（正数四舍五入，负数五舍六入）</span></span><br><span class="line"></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="title class_">Math</span>.<span class="title function_">random</span>());        <span class="comment">//生成0-1之间的随机数</span></span><br></pre>

<p>运行结果：</p>
<pre class="highlight"><span class="line">0.6</span><br><span class="line"></span><br><span class="line">-1</span><br><span class="line"></span><br><span class="line">-0</span><br><span class="line"></span><br><span class="line">-1</span><br><span class="line"></span><br><span class="line">0.6453756205275165</span><br></pre>

<h2 id="Math-abs-：获绝对值"><a href="#Math-abs-：获绝对值" class="headerlink" title="Math.abs()：获绝对值"></a>Math.abs()：获绝对值</h2><p>方法定义：返回绝对值。</p>
<p>注意：</p>
<ul>
<li>参数中可以接收字符串类型的数字，此时会将字符串做隐式类型转换，然后再调用 Math.abs() 方法。</li>
</ul>
<p>代码举例：</p>
<pre class="highlight"><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="title class_">Math</span>.<span class="title function_">abs</span>(<span class="number">2</span>)); <span class="comment">// 2</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="title class_">Math</span>.<span class="title function_">abs</span>(-<span class="number">2</span>)); <span class="comment">// 2</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 先做隐式类型转换，将 &#x27;-2&#x27;转换为数字类型 -2，然后再调用 Math.abs()</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="title class_">Math</span>.<span class="title function_">abs</span>(<span class="string">&#x27;-2&#x27;</span>));</span><br><span class="line"></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="title class_">Math</span>.<span class="title function_">abs</span>(<span class="string">&#x27;hello&#x27;</span>)); <span class="comment">// NaN</span></span><br></pre>

<h2 id="Math-random-方法：生成随机数"><a href="#Math-random-方法：生成随机数" class="headerlink" title="Math.random() 方法：生成随机数"></a>Math.random() 方法：生成随机数</h2><p>方法定义：生成 [0, 1) 之间的<strong>随机浮点数</strong>。</p>
<p>我们来看几个例子。</p>
<h3 id="生成-0-x-之间的随机数"><a href="#生成-0-x-之间的随机数" class="headerlink" title="生成 [0, x) 之间的随机数"></a>生成 [0, x) 之间的随机数</h3><pre class="highlight"><span class="line"><span class="title class_">Math</span>.<span class="title function_">round</span>(<span class="title class_">Math</span>.<span class="title function_">random</span>()*x)</span><br></pre>


<h3 id="生成-x-y-之间的随机数"><a href="#生成-x-y-之间的随机数" class="headerlink" title="生成 [x, y) 之间的随机数"></a>生成 [x, y) 之间的随机数</h3><pre class="highlight"><span class="line"><span class="title class_">Math</span>.<span class="title function_">round</span>(<span class="title class_">Math</span>.<span class="title function_">random</span>()*(y-x)+x)</span><br></pre>

<h3 id="【重要】生成-x-y-之间的随机整数"><a href="#【重要】生成-x-y-之间的随机整数" class="headerlink" title="【重要】生成 [x, y]之间的随机整数"></a>【重要】生成 [x, y]之间的随机整数</h3><p>也就是说：生成两个整数之间的随机整数，<strong>并且要包含这两个整数</strong>。</p>
<p>这个功能很常用，我们可以将其封装成一个方法，代码实现如下：</p>
<pre class="highlight"><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">* 生成两个整数之间的随机整数，并且要包含这两个整数</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">getRandom</span>(<span class="params">min, max</span>) &#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="title class_">Math</span>.<span class="title function_">floor</span>(<span class="title class_">Math</span>.<span class="title function_">random</span>() * (max - min + <span class="number">1</span>)) + min;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="title function_">getRandom</span>(<span class="number">1</span>, <span class="number">10</span>));</span><br></pre>

<h3 id="举例：随机点名"><a href="#举例：随机点名" class="headerlink" title="举例：随机点名"></a>举例：随机点名</h3><p>根据上面的例子，我们还可以再延伸一下，来看看随机点名的例子。</p>
<pre class="highlight"><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">* 生成两个整数之间的随机整数，并且要包含这两个整数</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">getRandom</span>(<span class="params">min, max</span>) &#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="title class_">Math</span>.<span class="title function_">floor</span>(<span class="title class_">Math</span>.<span class="title function_">random</span>() * (max - min + <span class="number">1</span>)) + min;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> arr = [<span class="string">&#x27;许嵩&#x27;</span>, <span class="string">&#x27;邓紫棋&#x27;</span>, <span class="string">&#x27;毛不易&#x27;</span>, <span class="string">&#x27;解忧邵帅&#x27;</span>];</span><br><span class="line"><span class="keyword">const</span> index = <span class="title function_">getRandom</span>(<span class="number">0</span>, arr.<span class="property">length</span> - <span class="number">1</span>); <span class="comment">// 生成随机的index</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(arr[index]); <span class="comment">// 随机点名</span></span><br></pre>


<h2 id="pow-：乘方"><a href="#pow-：乘方" class="headerlink" title="pow()：乘方"></a>pow()：乘方</h2><p>如果想计算 <code>a 的 b 次方</code>，可以使用如下函数：</p>
<pre class="highlight"><span class="line">Math.pow(a, b);</span><br></pre>

<p>Math的中文是“数学”，pow是“幂”。</p>
<p><strong>举例1：</strong></p>
<p><img  srcset="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20300%20300'%3E%3C/svg%3E" data-src="http://img.smyhvae.com/20180117_1730.png" class="lozad post-image"src="http://img.smyhvae.com/20180117_1730.png"></p>
<p>代码实现：</p>
<pre class="highlight"><span class="line">var a = Math.pow(3, Math.pow(2, 2));</span><br><span class="line">console.log(a);</span><br></pre>

<p><strong>举例2：</strong></p>
<p><img  srcset="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20300%20300'%3E%3C/svg%3E" data-src="http://img.smyhvae.com/20180117_1740.png" class="lozad post-image"src="http://img.smyhvae.com/20180117_1740.png"></p>
<p>代码实现：</p>
<pre class="highlight"><span class="line">var a = Math.pow(Math.pow(3, 2), 4);</span><br><span class="line">console.log(a);</span><br></pre>

<h2 id="sqrt-：开方"><a href="#sqrt-：开方" class="headerlink" title="sqrt()：开方"></a>sqrt()：开方</h2><p>如果想计算数值a的开二次方，可以使用如下函数：</p>
<pre class="highlight"><span class="line">Math.sqrt(a);</span><br></pre>

<p>sqrt即“square 开方”。比如：</p>
<pre class="highlight"><span class="line">var a = Math.sqrt(36);</span><br></pre>


<h2 id="url-编码和解码"><a href="#url-编码和解码" class="headerlink" title="url 编码和解码"></a>url 编码和解码</h2><p>URI (Uniform ResourceIdentifiers,通用资源标识符)进行编码，以便发送给浏览器。有效的URI中不能包含某些字符，例如空格。而这URI编码方法就可以对URI进行编码，它们用特殊的UTF-8编码替换所有无效的字符，从而让浏览器能够接受和理解。</p>
<pre class="highlight"><span class="line"><span class="built_in">encodeURIComponent</span>();   <span class="comment">//把字符串作为 URI 组件进行编码</span></span><br><span class="line"><span class="built_in">decodeURIComponent</span>();   <span class="comment">//把字符串作为 URI 组件进行解码</span></span><br></pre>

<p>举例：</p>
<pre class="highlight"><span class="line"><span class="keyword">var</span> url = <span class="string">&quot;http://www.cnblogs.com/smyhvae/&quot;</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> str = <span class="built_in">encodeURIComponent</span>(url);</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(str);                           <span class="comment">//打印url的编码</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="built_in">decodeURIComponent</span>(str));       <span class="comment">//对url进行编码后，再解码，还原为url</span></span><br></pre>

<p>打印结果：</p>
<p><img  srcset="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20300%20300'%3E%3C/svg%3E" data-src="http://img.smyhvae.com/20180202_1432.png" class="lozad post-image"src="http://img.smyhvae.com/20180202_1432.png"></p>
<h2 id="赞赏作者"><a href="#赞赏作者" class="headerlink" title="赞赏作者"></a>赞赏作者</h2><p>创作不易，你的赞赏和认可，是我更新的最大动力：</p>
<p><img  srcset="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20300%20300'%3E%3C/svg%3E" data-src="https://img.smyhvae.com/20220401_1800.jpg" class="lozad post-image"src="https://img.smyhvae.com/20220401_1800.jpg"></p>

  </div>
  <div>
    
      <div 
        class="post-note note-warning copyright" 
        style="margin-top: 42px">
        <p>
          <span style="font-weight: bold;">作者：</span><a 
            target="_blank" 
            rel="nofollow noopener noreferrer" 
            href="/about">
            zwl5670
          </a>
        </p>
        <p>
          <span style="font-weight: bold;">文章链接：</span><a 
            target="_blank" 
            rel="nofollow noopener noreferrer" 
            href="https://zwl5670.gitee.io/2004/03/01/04-JavaScript%E5%9F%BA%E7%A1%80/16-%E5%86%85%E7%BD%AE%E5%AF%B9%E8%B1%A1%EF%BC%9ANumber%E5%92%8CMath/">
            https://zwl5670.gitee.io/2004/03/01/04-JavaScript%E5%9F%BA%E7%A1%80/16-%E5%86%85%E7%BD%AE%E5%AF%B9%E8%B1%A1%EF%BC%9ANumber%E5%92%8CMath/
          </a>
        </p>
        <p><span style="font-weight: bold;">版权声明：</span>本博客所有文章除特别声明外，均采用<a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh">CC BY-NC-SA 4.0 协议</a>。转载请注明出处！</p>
      </div>
    
  </div>
</article>
<div class="nav">
  
    <div class="nav-item-prev">
      <a 
        href="/2004/03/01/04-JavaScript%E5%9F%BA%E7%A1%80/14-%E5%9F%BA%E6%9C%AC%E5%8C%85%E8%A3%85%E7%B1%BB%E5%9E%8B/" 
        class="nav-link">
        <i class="iconfont icon-left nav-prev-icon"></i>
        <div>
          <div class="nav-label">上一篇</div>
          
            <div class="nav-title">14-基本包装类型 </div>
          
        </div>
      </a>
    </div>
  
  
    <div class="nav-item-next">
      <a 
        href="/2004/03/01/04-JavaScript%E5%9F%BA%E7%A1%80/15-%E5%86%85%E7%BD%AE%E5%AF%B9%E8%B1%A1%20String%EF%BC%9A%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%9A%84%E5%B8%B8%E8%A7%81%E6%96%B9%E6%B3%95/" 
        class="nav-link">
        <div>
          <div class="nav-label">下一篇</div>
          
            <div class="nav-title">15-内置对象 String：字符串的常见方法 </div>
          
        </div>
        <i class="iconfont icon-right nav-next-icon"></i>
      </a>
    </div>
  
</div>

<div 
  class="card card-content toc-card" 
  id="mobiletoc">
  <div class="toc-header">
  <i 
    class="iconfont icon-menu" 
    style="padding-right: 2px;">
  </i>目录
</div>
<ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%86%85%E7%BD%AE%E5%AF%B9%E8%B1%A1-Number-%E7%9A%84%E5%B8%B8%E8%A7%81%E6%96%B9%E6%B3%95"><span class="toc-text">内置对象 Number 的常见方法</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Number-isInteger-%E5%88%A4%E6%96%AD%E6%98%AF%E5%90%A6%E4%B8%BA%E6%95%B4%E6%95%B0"><span class="toc-text">Number.isInteger() 判断是否为整数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#toFixed-%E5%B0%8F%E6%95%B0%E7%82%B9%E5%90%8E%E9%9D%A2%E4%BF%9D%E7%95%99%E5%A4%9A%E5%B0%91%E4%BD%8D"><span class="toc-text">toFixed() 小数点后面保留多少位</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%86%85%E7%BD%AE%E5%AF%B9%E8%B1%A1-Math-%E7%9A%84%E5%B8%B8%E8%A7%81%E6%96%B9%E6%B3%95"><span class="toc-text">内置对象 Math 的常见方法</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Math-abs-%EF%BC%9A%E8%8E%B7%E7%BB%9D%E5%AF%B9%E5%80%BC"><span class="toc-text">Math.abs()：获绝对值</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Math-random-%E6%96%B9%E6%B3%95%EF%BC%9A%E7%94%9F%E6%88%90%E9%9A%8F%E6%9C%BA%E6%95%B0"><span class="toc-text">Math.random() 方法：生成随机数</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%94%9F%E6%88%90-0-x-%E4%B9%8B%E9%97%B4%E7%9A%84%E9%9A%8F%E6%9C%BA%E6%95%B0"><span class="toc-text">生成 [0, x) 之间的随机数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%94%9F%E6%88%90-x-y-%E4%B9%8B%E9%97%B4%E7%9A%84%E9%9A%8F%E6%9C%BA%E6%95%B0"><span class="toc-text">生成 [x, y) 之间的随机数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E3%80%90%E9%87%8D%E8%A6%81%E3%80%91%E7%94%9F%E6%88%90-x-y-%E4%B9%8B%E9%97%B4%E7%9A%84%E9%9A%8F%E6%9C%BA%E6%95%B4%E6%95%B0"><span class="toc-text">【重要】生成 [x, y]之间的随机整数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%BE%E4%BE%8B%EF%BC%9A%E9%9A%8F%E6%9C%BA%E7%82%B9%E5%90%8D"><span class="toc-text">举例：随机点名</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#pow-%EF%BC%9A%E4%B9%98%E6%96%B9"><span class="toc-text">pow()：乘方</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#sqrt-%EF%BC%9A%E5%BC%80%E6%96%B9"><span class="toc-text">sqrt()：开方</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#url-%E7%BC%96%E7%A0%81%E5%92%8C%E8%A7%A3%E7%A0%81"><span class="toc-text">url 编码和解码</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%B5%9E%E8%B5%8F%E4%BD%9C%E8%80%85"><span class="toc-text">赞赏作者</span></a></li></ol>
</div>
            </main>
            <aside class="right-column">
              <div class="sticky-widescreen">
  
  
    <article class="card card-content toc-card">
      <div class="toc-header">
  <i 
    class="iconfont icon-menu" 
    style="padding-right: 2px;">
  </i>目录
</div>
<ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%86%85%E7%BD%AE%E5%AF%B9%E8%B1%A1-Number-%E7%9A%84%E5%B8%B8%E8%A7%81%E6%96%B9%E6%B3%95"><span class="toc-text">内置对象 Number 的常见方法</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Number-isInteger-%E5%88%A4%E6%96%AD%E6%98%AF%E5%90%A6%E4%B8%BA%E6%95%B4%E6%95%B0"><span class="toc-text">Number.isInteger() 判断是否为整数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#toFixed-%E5%B0%8F%E6%95%B0%E7%82%B9%E5%90%8E%E9%9D%A2%E4%BF%9D%E7%95%99%E5%A4%9A%E5%B0%91%E4%BD%8D"><span class="toc-text">toFixed() 小数点后面保留多少位</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%86%85%E7%BD%AE%E5%AF%B9%E8%B1%A1-Math-%E7%9A%84%E5%B8%B8%E8%A7%81%E6%96%B9%E6%B3%95"><span class="toc-text">内置对象 Math 的常见方法</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Math-abs-%EF%BC%9A%E8%8E%B7%E7%BB%9D%E5%AF%B9%E5%80%BC"><span class="toc-text">Math.abs()：获绝对值</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Math-random-%E6%96%B9%E6%B3%95%EF%BC%9A%E7%94%9F%E6%88%90%E9%9A%8F%E6%9C%BA%E6%95%B0"><span class="toc-text">Math.random() 方法：生成随机数</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%94%9F%E6%88%90-0-x-%E4%B9%8B%E9%97%B4%E7%9A%84%E9%9A%8F%E6%9C%BA%E6%95%B0"><span class="toc-text">生成 [0, x) 之间的随机数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%94%9F%E6%88%90-x-y-%E4%B9%8B%E9%97%B4%E7%9A%84%E9%9A%8F%E6%9C%BA%E6%95%B0"><span class="toc-text">生成 [x, y) 之间的随机数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E3%80%90%E9%87%8D%E8%A6%81%E3%80%91%E7%94%9F%E6%88%90-x-y-%E4%B9%8B%E9%97%B4%E7%9A%84%E9%9A%8F%E6%9C%BA%E6%95%B4%E6%95%B0"><span class="toc-text">【重要】生成 [x, y]之间的随机整数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%BE%E4%BE%8B%EF%BC%9A%E9%9A%8F%E6%9C%BA%E7%82%B9%E5%90%8D"><span class="toc-text">举例：随机点名</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#pow-%EF%BC%9A%E4%B9%98%E6%96%B9"><span class="toc-text">pow()：乘方</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#sqrt-%EF%BC%9A%E5%BC%80%E6%96%B9"><span class="toc-text">sqrt()：开方</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#url-%E7%BC%96%E7%A0%81%E5%92%8C%E8%A7%A3%E7%A0%81"><span class="toc-text">url 编码和解码</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%B5%9E%E8%B5%8F%E4%BD%9C%E8%80%85"><span class="toc-text">赞赏作者</span></a></li></ol>
    </article>
  
  
  <article class="card card-content">
    <div class="recent-posts-card">
  <div class="recent-posts-header">
    <i 
      class="iconfont icon-wenzhang_huaban" 
      style="padding-right: 2px;">
    </i>最近文章
  </div>
  <div class="recent-posts-list">
    
      <div class="recent-posts-item">
        <div class="recent-posts-item-title">2023-03-09</div>
        <a href="/2023/03/09/13-React%E5%9F%BA%E7%A1%80/11-React%20Navive%E5%88%9D%E8%AF%86/"><div class="recent-posts-item-content">11-React Navive初识</div></a>
      </div>
    
      <div class="recent-posts-item">
        <div class="recent-posts-item-title">2023-03-09</div>
        <a href="/2023/03/09/13-React%E5%9F%BA%E7%A1%80/10-AntD%E6%A1%86%E6%9E%B6%E7%9A%84upload%E7%BB%84%E4%BB%B6%E4%B8%8A%E4%BC%A0%E5%9B%BE%E7%89%87%E6%97%B6%E4%BD%BF%E7%94%A8customRequest%E6%96%B9%E6%B3%95%E8%87%AA%E5%AE%9A%E4%B9%89%E4%B8%8A%E4%BC%A0%E8%A1%8C%E4%B8%BA/"><div class="recent-posts-item-content">10-AntD框架的upload组件上传图片时使用customRequest方法自定义上传行为</div></a>
      </div>
    
      <div class="recent-posts-item">
        <div class="recent-posts-item-title">2023-03-09</div>
        <a href="/2023/03/09/13-React%E5%9F%BA%E7%A1%80/09-AntD%E6%A1%86%E6%9E%B6%E7%9A%84upload%E7%BB%84%E4%BB%B6%E4%B8%8A%E4%BC%A0%E5%9B%BE%E7%89%87%E6%97%B6%E9%81%87%E5%88%B0%E7%9A%84%E4%B8%80%E4%BA%9B%E5%9D%91/"><div class="recent-posts-item-content">09-AntD框架的upload组件上传图片时遇到的一些坑</div></a>
      </div>
    
      <div class="recent-posts-item">
        <div class="recent-posts-item-title">2023-03-09</div>
        <a href="/2023/03/09/13-React%E5%9F%BA%E7%A1%80/08-Ant%20Design%E7%9A%84%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8/"><div class="recent-posts-item-content">08-Ant Design的基本使用</div></a>
      </div>
    
  </div>
</div>
  </article>
  
  
</div>
            </aside>
          </div>
        </div>
      </div>
    </div>
     
    <footer class="footer">
  <div class="footer-container">
    <div>
      <div class="footer-dsc">
        <span>
          Copyright ©
          
            2023
          
          
        </span>
        &nbsp;
        <a 
          href="/" 
          class="footer-link">
          前端面试
        </a>
      </div>
    </div>

    
      <div class="footer-dsc">
        
          Powered by
          <a 
            href="https://hexo.io/" 
            class="footer-link" 
            target="_blank" 
            rel="nofollow noopener noreferrer">
            &nbsp;Hexo
          </a>
        
        
          <span>&nbsp;|&nbsp;</span>
        
        
          Theme -
          <a 
            href="https://github.com/theme-kaze" 
            class="footer-link" 
            target="_blank"
            rel="nofollow noopener noreferrer">
            &nbsp;Kaze
          </a>
        
      </div>
    
    
    
    
</footer>
 
    
  <a 
    role="button" 
    id="scrollbutton" 
    class="basebutton" 
    aria-label="回到顶部">
    <i class="iconfont icon-arrowleft button-icon"></i>
  </a>

<a 
  role="button" 
  id="menubutton"
  aria-label="menu button"
  class="basebutton">
  <i class="iconfont icon-menu button-icon"></i>
</a>
<a 
  role="button" 
  id="popbutton" 
  class="basebutton" 
  aria-label="控制中心">
  <i class="iconfont icon-expand button-icon"></i>
</a>
<a 
  role="button" 
  id="darkbutton" 
  class="basebutton darkwidget" 
  aria-label="夜色模式">
  <i class="iconfont icon-weather button-icon"></i>
</a>
<a 
  role="button" 
  id="searchbutton" 
  class="basebutton searchwidget" 
  aria-label="搜索">
  <i class="iconfont icon-search button-icon"></i>
</a> 
     
     
     
      <script>
  var addImgLayout = function () {
    var img = document.querySelectorAll('.post-content img')
    var i
    for (i = 0; i < img.length; i++) {
      var wrapper = document.createElement('a')
      wrapper.setAttribute('href', img[i].getAttribute('data-src'))
      wrapper.setAttribute('aria-label', 'illustration')
      wrapper.style.cssText =
        'width: 100%; display: flex; justify-content: center;'
      if (img[i].alt) wrapper.dataset.caption = img[i].alt
      wrapper.dataset.nolink = true
      img[i].before(wrapper)
      wrapper.append(img[i])
      var divWrap = document.createElement('div')
      divWrap.classList.add('gallery')
      wrapper.before(divWrap)
      divWrap.append(wrapper)
    }
    baguetteBox.run('.gallery')
  }
</script>
<script>
  loadScript(
    "/js/lib/lightbox/baguetteBox.min.js",
    addImgLayout
  )
</script>
 
     
     
    <script src="/js/main.js"></script> 
     
    
      <script>
        var addLazyload = function () {
          var observer = lozad('.lozad', {
            load: function (el) {
              el.srcset = el.getAttribute('data-src')
            },
            loaded: function (el) {
              el.classList.add('loaded')
            },
          })
          observer.observe()
        }
      </script>
      <script>
        loadScript('/js/lib/lozad.min.js', addLazyload)
      </script>
    
    <script src="//instant.page/5.1.0" type="module"
      integrity="sha384-by67kQnR+pyfy8yWP4kPO12fHKRLHZPfEsiSXR8u2IKcTdxD805MGUXBzVPnkLHw"></script>
    
    
  </body>
</html>
